package com.ruoyi.app.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.app.domain.vo.DebtRecordsVo;
import com.ruoyi.app.domain.vo.OrderInfoVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.app.domain.DebtRecords;
import com.ruoyi.app.service.IDebtRecordsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 供应商信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-29
 */
@RestController
@RequestMapping("/debt/debtRecords")
public class DebtRecordsController extends BaseController
{
    @Autowired
    private IDebtRecordsService debtRecordsService;

    /**
     * 查询供应商信息列表
     */
    @GetMapping("/list")
    public AjaxResult list(DebtRecordsVo debtRecordsVo)
    {
        startPage();
        debtRecordsVo.setShopId(getShopId());
        List<DebtRecordsVo> list = debtRecordsService.selectDebtRecordsList(debtRecordsVo);
        return success(getDataTable(list));
    }

    /**
     * 导出供应商信息列表
     */
    @PreAuthorize("@ss.hasPermi('debt:debtRecords:export')")
    @Log(title = "供应商信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DebtRecordsVo debtRecordsVo)
    {
        List<DebtRecordsVo> list = debtRecordsService.selectDebtRecordsList(debtRecordsVo);
        ExcelUtil<DebtRecordsVo> util = new ExcelUtil<DebtRecordsVo>(DebtRecordsVo.class);
        util.exportExcel(response, list, "供应商信息数据");
    }

    /**
     * 获取供应商信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('debt:debtRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(debtRecordsService.selectDebtRecordsById(id));
    }

    /**
     * 新增供应商信息
     */
//    @PreAuthorize("@ss.hasPermi('debt:debtRecords:add')")
    @Log(title = "供应商信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DebtRecordsVo debtRecordsVo)
    {
        debtRecordsVo.setShopId(getShopId());
        return success().setData(debtRecordsService.add(debtRecordsVo));
    }

    /**
     * 修改供应商信息
     */
    @PreAuthorize("@ss.hasPermi('debt:debtRecords:edit')")
    @Log(title = "供应商信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody DebtRecords debtRecords)
    {
        return toAjax(debtRecordsService.updateById(debtRecords));
    }

    /**
     * 删除供应商信息
     */
//    @PreAuthorize("@ss.hasPermi('debt:debtRecords:remove')")
    @Log(title = "供应商信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        List<String> objects = Arrays.asList(ids);
        return toAjax(debtRecordsService.removeByIds(objects));
    }
}
